package com.houweishi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.houweishi.common.annotation.Log;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.system.domain.TRecyclingType;
import com.houweishi.system.service.ITRecyclingTypeService;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.common.core.page.TableDataInfo;

/**
 * 回收种类信息Controller
 * 
 * @author houweishi
 * @date 2022-11-27
 */
@Controller
@RequestMapping("/system/recycling")
public class TRecyclingTypeController extends BaseController
{
    private String prefix = "system/recycling";

    @Autowired
    private ITRecyclingTypeService tRecyclingTypeService;

    @RequiresPermissions("system:recycling:view")
    @GetMapping()
    public String recycling()
    {
        return prefix + "/recycling";
    }

    /**
     * 查询回收种类信息列表
     */
    @RequiresPermissions("system:recycling:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TRecyclingType tRecyclingType)
    {
        startPage();
        List<TRecyclingType> list = tRecyclingTypeService.selectTRecyclingTypeList(tRecyclingType);
        return getDataTable(list);
    }

    /**
     * 导出回收种类信息列表
     */
    @RequiresPermissions("system:recycling:export")
    @Log(title = "回收种类信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TRecyclingType tRecyclingType)
    {
        List<TRecyclingType> list = tRecyclingTypeService.selectTRecyclingTypeList(tRecyclingType);
        ExcelUtil<TRecyclingType> util = new ExcelUtil<TRecyclingType>(TRecyclingType.class);
        return util.exportExcel(list, "回收种类信息数据");
    }

    /**
     * 新增回收种类信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存回收种类信息
     */
    @RequiresPermissions("system:recycling:add")
    @Log(title = "回收种类信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TRecyclingType tRecyclingType)
    {
        return toAjax(tRecyclingTypeService.insertTRecyclingType(tRecyclingType));
    }

    /**
     * 修改回收种类信息
     */
    @RequiresPermissions("system:recycling:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TRecyclingType tRecyclingType = tRecyclingTypeService.selectTRecyclingTypeById(id);
        mmap.put("tRecyclingType", tRecyclingType);
        return prefix + "/edit";
    }

    /**
     * 修改保存回收种类信息
     */
    @RequiresPermissions("system:recycling:edit")
    @Log(title = "回收种类信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TRecyclingType tRecyclingType)
    {
        return toAjax(tRecyclingTypeService.updateTRecyclingType(tRecyclingType));
    }

    /**
     * 删除回收种类信息
     */
    @RequiresPermissions("system:recycling:remove")
    @Log(title = "回收种类信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tRecyclingTypeService.deleteTRecyclingTypeByIds(ids));
    }
}
